package com.ruoyi.core.controller.mWeb;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.email.EmailUtils;
import com.ruoyi.core.lock.ULock;
import com.ruoyi.core.service.MSearchService;
import com.ruoyi.core.vo.SearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * @Author xiaom
 * @Date 2021/1/26 16:23
 * @Version 1.0.0
 * @Description <>
 **/
@Api(tags = "通用查询接口")
@RestController
@RequestMapping("/search")
@Slf4j
public class MSearchController {

    @Autowired
    private MSearchService mSearchService;

    @Autowired
    private EmailUtils emailUtils;

    @PostMapping(value = "/v1")
    @ApiOperation("公共查询接口")
    public Object search(@RequestBody @Valid SearchVo searchVo){
        log.info("Path:{}",searchVo.getPath());
        return mSearchService.request(searchVo);
    }

    @GetMapping(value = "/clearCache")
    @ApiOperation("清理查询缓存")
    public AjaxResult clearCache(){
        return AjaxResult.success(mSearchService.clearCache());
    }

    @GetMapping("/getAllMerchantCookies")
    @ApiOperation("获取所有的cookie")
    public AjaxResult getAllMerchantCookies(){
        return AjaxResult.success();
    }

    @GetMapping(value = "/testEmail")
    public AjaxResult testEmail(){
        emailUtils.sendSimpleMail("2210465185@qq.com","test","测试邮件发送");
        return AjaxResult.success();
    }
}
